package com.azdebugit.java8.suanfa.mingan;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @date 2021/9/30 10:01
 * <p>
 * 违禁词外部文件加载器(加载服务器内部,jar包外部)
 */
@SuppressWarnings("unused")
public class SensitiveWordExternalFileLoader extends SensitiveWordAbstractFileLoader {

    public SensitiveWordExternalFileLoader(String externalFileAbsolutePath, String separator) {
        this(externalFileAbsolutePath, StandardCharsets.UTF_8, separator);
    }

    public SensitiveWordExternalFileLoader(String externalFileAbsolutePath) {
        this(externalFileAbsolutePath, ",");
    }

    /**
     * 构造器
     *
     * @param externalFileAbsolutePath 违禁词文件的绝对路径
     * @param charset                  字符集
     * @param separator                违禁词分隔符
     */
    public SensitiveWordExternalFileLoader(String externalFileAbsolutePath, Charset charset, String separator) {
        super(externalFileAbsolutePath, charset, separator);
    }

    @Override
    public void initInputStream() {
        File file = new File(filePath);
        try {
            inputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException("external sensitive word file not found,filePath = " + filePath);
        }
    }
}